package cn.tedu.controller;

import cn.tedu.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.common.web.JsonResult;
import cn.tedu.pojo.param.UserDetailsParam;
import cn.tedu.pojo.param.WorkExperienceParam;
import cn.tedu.pojo.vo.UserDetailsVO;
import cn.tedu.pojo.vo.WorkExperienceVO;
import cn.tedu.service.IUserDetailsService;
import cn.tedu.service.IWorkExperienceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/biographicalNotes")
public class BiographicalNotesController {
    @Autowired
    private IUserDetailsService userDetailsService;
    @Autowired
    private IWorkExperienceService workExperienceService;

    @PostMapping("/userDetails/add-new")
    @ApiOperation("添加用户详情")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(CurrentPrincipal currentPrincipal, UserDetailsParam userDetailsParam){
        userDetailsService.insert(currentPrincipal, userDetailsParam);
        return JsonResult.ok();
    }

    @PostMapping("/userDetails/{id}")
    @ApiOperation("根据id查询用户详情")
    @ApiOperationSupport(order = 200)
    public JsonResult getUserDetails(Long userId){
        return JsonResult.ok(userDetailsService.getStandard(userId));
    }

    @PostMapping("/userDetails/{id:[0-9]+}/info/update")
    @ApiOperation("修改基本信息")
    @ApiOperationSupport(order = 300)
    public JsonResult updateInfo(Long userId, UserDetailsParam userDetailsParam) {
        userDetailsService.updateInfo(userId, userDetailsParam);
        return JsonResult.ok();
    }

    @PostMapping("/userDetails/{id:[0-9]+}/userUrl/update")
    @ApiOperation("修改头像")
    @ApiOperationSupport(order = 320)
    public JsonResult updateUserUrl(Long userId, String userUrl) {
        userDetailsService.updateUserUrl(userId, userUrl);
        return JsonResult.ok();
    }

    @PostMapping("/userDetails/{id:[0-9]+}/phone/update")
    @ApiOperation("修改手机号码")
    @ApiOperationSupport(order = 330)
    public JsonResult updatePhone(Long userId, String phone) {
        userDetailsService.updatePhoneNumber(userId, phone);
        return JsonResult.ok();
    }

    @PostMapping("/userDetails/{id:[0-9]+}/email/update")
    @ApiOperation("修改电子邮箱")
    @ApiOperationSupport(order = 340)
    public JsonResult updateEmail(Long userId, String email) {
        userDetailsService.updateEmail(userId, email);
        return JsonResult.ok();
    }

    @PostMapping("/workExperience/add-new")
    @ApiOperation("添加工作经历")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(CurrentPrincipal currentPrincipal, WorkExperienceParam workExperienceParam){
        workExperienceService.addNew(currentPrincipal, workExperienceParam);
        return JsonResult.ok();
    }

    @PostMapping("/workExperience/{id}")
    @ApiOperation("根据id查询工作经历")
    @ApiOperationSupport(order = 200)
    public JsonResult getWorkExperience(Long id){
        return JsonResult.ok(workExperienceService.getStandard(id));
    }

    @PostMapping("/workExperience/{id:[0-9]+}/update")
    @ApiOperation(("修改工作经历"))
    @ApiOperationSupport(order = 300)
    public JsonResult update(Long id,WorkExperienceParam workExperienceParam){
        workExperienceService.updateById(id,workExperienceParam);
        return JsonResult.ok();
    }

    @PostMapping("/workExperience/{id:[0-9]+}/list")
    @ApiOperation("根据用户id查询所有工作经历")
    @ApiOperationSupport(order = 400)
    public JsonResult listOfWorkExperience(Long userId){
        List<WorkExperienceVO> list = workExperienceService.list(userId);
        return JsonResult.ok(list);
    }
}
